#pragma once

#include <QtNetwork/QAbstractSocket>
#include <boost/iostreams/concepts.hpp>
#include <boostext/signal.hpp>




namespace Engine
{
	namespace Edit
	{
		/**
		 * This class models the concept of a bidirectional device.
		 * It does so by delegating read/write calls to an instance
		 * of QAbstractSocket
		 */
		class SocketStreamDevice
		{
		public:

			// Make this class device compliant: We're sending signed characters
			typedef char                                         char_type;
			typedef boost::iostreams::bidirectional_device_tag   category;



			SocketStreamDevice(QAbstractSocket* socket);
			virtual ~SocketStreamDevice();



			/**
			 * Reads up to n characters from the tcp data stream.
			 */
			std::streamsize read(char* s, std::streamsize n);

			/**
			 * Writes up to n characters to the tcp data stream.
			 */
			std::streamsize write(const char* s, std::streamsize n);

			/**
			 * @throws not_implemented_exception
			 */
			std::streamsize seek(boost::iostreams::stream_offset off, std::ios_base::seekdir way);

		private:

			QAbstractSocket*   m_socket;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
